﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Incendios0_1.sms
{
    /// <summary>
    /// Interaction logic for delete_sms_contact.xaml
    /// </summary>
    public partial class delete_sms_contact : Window
    {
        public delete_sms_contact()
        {
            InitializeComponent();
        }

        private void deletecontact_Click(object sender, RoutedEventArgs e)
        {
            erase();
        }

        private void Canceldeletecontact_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                erase();
        }

        private void erase()
        {
            Contacts contact = ContactControler.SearchContactByPhone(textBox1.Value.ToString());
            if (contact == null)
            {
                Microsoft.Windows.Controls.MessageBox.Show("El contacto no existe", "No encontrado", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                MessageBoxResult result = Microsoft.Windows.Controls.MessageBox.Show("Realmente desea borrar el contacto " + contact.Name + "\n con número " + contact.Phone, "Borrar", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    ContactControler.Delete(contact);
                }
            }
        }


    }
}
